<?php

vendor('abstract_object');

class __LayoutObj extends AbstractObject
{
    //protected $_name = 'default';
    protected $_default_render = true;
    protected $_enabled_render = array();
    protected $_disabled_render = array();
    public $widget = array();

    function __construct()
    {
        parent::__construct();
    }

    /*function set($name)
    {
        $this->_name = $name;
    }*/

    function enabled($name)
    {
        if ($this->_default_render) {
            return !in_array($name, $this->_disabled_render);
        } else {
            return in_array($name, $this->_enabled_render);
        }
    }

    function enableAll()
    {
        $this->_default_render = true;
        $this->_enabled_render = array();
        $this->_disabled_render = array();
    }

    function disableAll()
    {
        $this->_default_render = false;
        $this->_enabled_render = array();
        $this->_disabled_render = array();
    }

    function enable($name)
    {
        if (! $this->enabled($name)) {
            if ($this->_default_render) {
                $keys = array_keys($this->_disabled_render, $name);
                foreach ($keys as $key) {
                    unset($this->_disabled_render[$key]);
                }
            } else {
                $this->_enabled_render[] = $name;
            }
        }
    }

    function disable($name)
    {
        if ($this->enabled($name)) {
            if (! $this->_default_render) {
                $keys = array_keys($this->_enabled_render, $name);
                foreach ($keys as $key) {
                    unset($this->_enabled_render[$key]);
                }
            } else {
                $this->_disabled_render[] = $name;
            }
        }
    }

}

class Layout
{
    /**
     *
     *
     * @return __LayoutObj
     */
    static function &o()
    {
        static $result;
        if (is_null($result)) {
            $result = new __LayoutObj();
        }
        return $result;
    }
}

?>